// pages/edituser/edituser.js
import cache from '../../utils/Cache.js';
import url from '../../utils/url.js';
import http from '../../utils/http.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userinfo: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    http.http(url.getuserinfo, 'GET', { openid: cache.getSorg('openid') }, function (res) {
      that.setData({
        userinfo: res.userinfo
      });
    });
  },
  formSubmit:function(e){
    var that = this;
      var postData = e.detail.value;
      console.log(postData)
      if (!postData.age || !postData.phone || !postData.nickname){
          wx.showToast({
            title: '请填写完整信息',
            icon:'none'
          })
          return false;
      }
      //调取接口，进行数据的修改
      postData.openid = cache.getSorg('openid')
      http.http(url.updateuserinfo,'POST',postData,function(res){
        wx.showToast({
          title: '保存成功',
        })
      that.setData({
        userinfo:res.data
      });
      })

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  }
})